import { _decorator, Component,Vec3,Vec2,tween, Node, Label, sp } from 'cc';
import { UICtrl } from '../../../Framework/Managers/UICtrl';
import { RoleCtrl } from '../../../Framework/Managers/RoleCtrl';
import { Globle } from '../../../Framework/Utils/Globle';
const { ccclass, property } = _decorator;

@ccclass('Player_Ctrl')
export class Player_Ctrl extends RoleCtrl {

    public id:number;
    public roomId:number = -1;
    private playerName:Label;
    
    onLoad(): void {
        super.onLoad();
        this.playerImg = this.getChildOrComponent("playerImg",sp.Skeleton);
        this.playerName = this.getChildOrComponent("PlayerNameBg/playerName",Label);
    }
    
    init(data){
        this.type = "player";
        this.skinName = "zise";
        if (data.rank == 1) {
            this.skinName = "jinse";
        }
        if (data.rank>=2&&data.rank<=5) {
            this.skinName = "chengse";
        }
        if (data.rank>=6&&data.rank<=10) {
            this.skinName = "lvse";
        }
        this.id = data.id;
        this.roomId = data.pos;
        this.playerImg.animation = this.skinName+"zhan";
        this.playerName.string = data.nickName;
        if (data.id == Globle.userData.id && data.nickName == Globle.userData.nickName) {
            this.playerName.string = "自己";
        }
    }

    move(pathData){
        this.movePosArr = pathData;
        this.moveDir = "forward"
        this.moveCharacter(0);
    }

    exit(playerPos){
        this.moveDir = "retreat"
        this.movePosArr.reverse();
        let playPos = new Vec3(0,0,0);
        playPos.x = Math.random()*playerPos.width-playerPos.width/2+playerPos.node.position.x;
        playPos.y = Math.random()*playerPos.height-playerPos.height/2+playerPos.node.position.y;
        this.movePosArr.push(playPos);
        this.moveCharacter(0);
    }

    die(){
        this.node.destroy();
    }
}


